home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Programming / SWI / source / src / pl-extend.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-26  |  1.9 KB  |  76 lines

  1. /*  $Id: pl-extend.c,v 1.13 1997/08/26 10:08:44 jan Exp $
  2.  
  3.     Copyright (c) 1991 Jan Wielemaker. All rights reserved.
  4.     jan@swi.psy.uva.nl
  5.  
  6.     Purpose: Skeleton for extensions
  7. */
  8.  
  9. #include <stdio.h>
  10. #include "pl-itf.h"
  11.  
  12. #define READLINE 1            /* use readline interface */
  13.  
  14. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  15. C-extensions can either be loaded through the foreign language interface
  16. using load_foreign_library/[1,2] or they can   be statically linked with
  17. the Prolog kernel.
  18.  
  19. In the latter case, proceed as follows:
  20.  
  21.   1) Make a copy of this file.  In this copy:
  22.   2) Fill the table below for adding foreign functions as predicates
  23.   3) Replace the main() below with your own main().  You can pass
  24.      the main arguments or your own argument (using the systems
  25.      conventions).  Make sure to pass the name of the program as
  26.      first argument.
  27.   4) Normally #undef READLINE (above), unless your embedded version
  28.      provided access to the Prolog toplevel for which you want to
  29.      use readline.
  30.   5) Use plld(1) to link this file, and possible Prolog sources to
  31.      a single executable:
  32.  
  33.     plld -o myprog myprog.c myprog.pl
  34.  
  35.      See main plld and/or the SWI-Prolog manuals for further details.
  36. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37.  
  38. PL_extension predicates[] =
  39. {
  40. /*{ "name",    arity,  function,    PL_FA_<flags> },*/
  41.  
  42.   { NULL,    0,     NULL,        0 }    /* terminating line */
  43. };
  44.  
  45.  
  46. #ifdef READLINE
  47. static void
  48. install_readline(int argc, char**argv)
  49. { PL_install_readline();
  50. }
  51. #endif
  52.  
  53. int
  54. main(int argc, char **argv)
  55. {
  56.  
  57. #ifdef READLINE
  58.   PL_initialise_hook(install_readline);
  59. #endif
  60.  
  61.   PL_register_extensions(predicates);    /* This is the only PL_ call allowed */
  62.                     /* before PL_initialise().  It */
  63.                     /* ensures the foreign predicates */
  64.                     /* are available before loading */
  65.                     /* Prolog code */
  66.  
  67.   if ( !PL_initialise(argc, argv) )
  68.     PL_halt(1);
  69.  
  70.   PL_halt(PL_toplevel() ? 0 : 1);
  71.  
  72.   return 0;
  73. }
  74.  
  75.  
  76.